| Conditions | 2 |
| Total Lines | 36 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import storage from "./storage"; |
||
| 10 | login: async function login(email, password) { |
||
| 11 | const data = { |
||
| 12 | email: email, |
||
| 13 | password: password, |
||
| 14 | api_key: process.env.REACT_APP_REST_API_KEY, |
||
| 15 | }; |
||
| 16 | const tokenObj = storage.readToken(); |
||
| 17 | const response = await fetch( |
||
| 18 | `${process.env.REACT_APP_API_URL}/auth/login/server/admin`, |
||
| 19 | { |
||
| 20 | method: "POST", |
||
| 21 | body: JSON.stringify(data), |
||
| 22 | headers: { |
||
| 23 | "content-type": "application/json", |
||
| 24 | "x-access-token": tokenObj.token, |
||
| 25 | }, |
||
| 26 | } |
||
| 27 | ); |
||
| 28 | const result = await response.json(); |
||
| 29 | |||
| 30 | if (Object.prototype.hasOwnProperty.call(result, "errors")) { |
||
| 31 | return { |
||
| 32 | message: result.errors.title, |
||
| 33 | description: result.errors.detail, |
||
| 34 | type: "danger", |
||
| 35 | }; |
||
| 36 | } |
||
| 37 | |||
| 38 | storage.storeToken(result.data.token); |
||
| 39 | |||
| 40 | return { |
||
| 41 | message: "Success", |
||
| 42 | description: result.data.message, |
||
| 43 | type: "success", |
||
| 44 | }; |
||
| 45 | }, |
||
| 46 | logout: async function logout() { |
||
| 52 |